# $Id: charsets.tcl 9 2007-06-23 23:59:54Z khomoutov $
# Character set mappings to/from Tcl encoding names and IANA MIBenums.
# Current set of encodings used is as in Tcl 8.5a6.

# cp936 is GBK.

# EBCDIC -- there're many EBCDIC's, Tcl's one is titled "EDF04"
# which Apache aliases as "osd_ebcdic_df04_1"
# (see http://apr.apache.org/docs/apr-iconv/1.1/charset__alias_8h-source.html)
# and so it's mapped to IANA MIBEnum 117.

# Macintosh encodings don't seem to have IANA MIBenums assigned.

namespace eval ::tclplkr {
	variable enc2iana
	array set enc2iana {
		ascii       3
		big5        2026
		cjk.inf     WHATSTHIS?
		cp1250      2250
		cp1251      2251
		cp1252      2252
		cp1253      2253
		cp1254      2254
		cp1255      2255
		cp1256      2256
		cp1257      2257
		cp1258      2258
		cp437       2011
		cp737       UNDEFINED
		cp775       2087
		cp850       2009
		cp852       2010
		cp855       2046
		cp857       2047
		cp860       2048
		cp861       2049
		cp862       2013
		cp863       2050
		cp864       2051
		cp865       2052
		cp866       2086
		cp869       2054
		cp874       UNDEFINED
		cp932       UNDEFINED
		cp936       113
		cp949       UNDEFINED
		cp950       UNDEFINED
		dingbats    UNDEFINED
		ebcdic      117
		gb12345     UNDEFINED
		gb1988      56
		gb2312      57
		iso8859-1   4
		iso8859-10  13
		iso8859-13  109
		iso8859-14  110
		iso8859-15  111
		iso8859-16  112
		iso8859-2   5
		iso8859-3   6
		iso8859-4   7
		iso8859-5   8
		iso8859-6   9
		iso8859-7   10
		iso8859-8   11
		iso8859-9   12
		jis0201     15
		jis0208     63
		jis0212     98
		koi8-r      2084
		ksc5601     36
		macCentEuro UNDEFINED
		macCroatian UNDEFINED
		macCyrillic UNDEFINED
		macDingbats UNDEFINED
		macGreek    UNDEFINED
		macIceland  UNDEFINED
		macJapan    UNDEFINED
		macRoman    UNDEFINED
		macRomania  UNDEFINED
		macThai     UNDEFINED
		macTurkish  UNDEFINED
		macUkraine  UNDEFINED
		shiftjis    17
		symbol      UNDEFINED
		tis-620     2259
	}

	variable iana2enc
	foreach enc [array names enc2iana] {
		set mibenum $enc2iana($enc)
		if {![string match $mibenum UNDEFINED]} {
			set iana2enc($mibenum) $enc
		}
	}
	unset enc

	proc enc2iana enc {
		variable enc2iana
		set enc2iana($enc)
	}

	proc iana2enc mibenum {
		variable iana2enc
		set iana2enc($mibenum)
	}

	proc mibenum {action args} {
		variable iana2enc
		switch -glob -- $action {
			*supported {
				return [info exists iana2enc([lindex $args 0])]
			}
			toenc* -
			totcl {
				return $iana2enc([lindex $args 0])
			}
		}
	}
}

